<?php
/**
 * Eren Framework
 * 
 * The PlugIn Container
 * 
 * @category System
 * @author Manu Soros Leu
 * @copyright manusoros@gmail.com
 */

class Eren_PlugIn
{
    
    /**
     * Used to store PlugIn
     * 
     * @var array
     */
    private static $_plugIns = array();
    
    /**
     * Regist PlugIn
     * 
     * @param Eren_PlubIn_Abtract $plugIn
     * @throws Eren_PlugIn_Exception
     */
    public static function regist($plugIn, $key = 0)
    {
        if(!Eren_Validator::isBaseClass($plugIn, 'Eren_PlugIn_Abstract')){
            throw new Eren_PlugIn_Exception('PlugIn must inherit from  Eren_PlugIn_Abstract');
        }
        if(is_array($key)){
            throw new Eren_PlugIn_Exception('The second param of regist cant be array');
        }
        if($key){
            self::$_plugIns[$key] = $plugIn;
        }else{
            self::$_plugIns[] = $plugIn;
        }
        
    }
    
    /**
     * Do every function beforeRouter of registed PlugIn
     */
    public static function beforeRouter()
    {
        if(!self::$_plugIns) return;
        foreach (self::$_plugIns as $plugIn){
            $plugIn->beforeRouter();
        }
    }
    
    /**
     * Do every function afterRouter of registed PlugIn
     */
    public static function afterRouter()
    {
        if(!self::$_plugIns) return;
        foreach (self::$_plugIns as $plugIn){
            $plugIn->afterRouter();
        }
    }
}